Expressions, Operators and Precedence


Overview

Expressions are pieces of Pog code which have an intrinsic value attached to them. They may perform work as a side-effect. The chain of expression rules defines the precedence of operators, which follow ANSI C precedence conventions. Not all C operators are implemented in Pog.

The following tables describe the operators supported by Pog, and their precedence.

 

Mathematical Operators

Operation Symbol Notes
Addition +
Subtraction -
Multiplication *
Division /
Modulo (remainder) % Returns the integer remainder after an integer division. i.e. 5%3 returns 2

 

Comparison Operators

Operation Symbol Notes
Equality ==
Inequality !=
Not !
Less Than <
Less Than or Equal <=
Greater Than >
Greater Than or Equal >=

 

 

Logical Operators

Operation Symbol Notes
And &&
Or ||
Not !

 

 

Bitwise Operators

Operation Symbol Notes
Bitwise And & 4 & 8 will yield 0
4 & 7 will yield 4
Bitwise Or | 4 & 8 will yield 12
4 & 7 will yield 7
Bitwise Exclusive Or ^ 4 ^ 8 will yield 12
4 ^ 7 will yield 3
Adds the bits that are only on in one of the two numbers
Bitwise Not ~

 

 

Assignment Operators

Operation Symbol Notes
Assignment = x = y will set x to the value of y
Additive Assignment += x += y will set x to the value of x + y
Subtractive Assignment -= x -= y will set x to the value of x - y
Multiplicative Assignment *= x *= y will set x to the value of x * y
Divisive Assignment /= x /=y will set x to the value of x / y
Remainder assignment %= x %=y will set x to the value of x % y
Bitwise And assignment &=
Bitwise Or assignment |=
Bitwise Xor assignment ^=
Bitwise Not assignment ~=
Auto Increment ++ x++ will increment x by 1 with the value returned being that of x
++x will increment x by 1 with the value returned being that of x+1
Auto Decrement -- As above

 

 

Order Of Precedence

Highest Precedence
++ Post-increment Left to right
-- Post-decrement Left to right
( ) Function call Left to right
[ ] Array element Left to right
++ Pre-increment Right to left
-- Pre-decrement Right to left
! Logical NOT Right to left
~ Bitwise NOT Right to left
- Unary minus Right to left
+ Unary plus Right to left
* Multiply Left to right
/ Divide Left to right
% Remainder Left to right
+ Add Left to right
- Subtract Left to right
<< Left shift Left to right
>> Right shift Left to right
< Less than Left to right
<= Less than or equal to Left to right
> Greater than Left to right
>= Greater than or equal to Left to right
== Equal Left to right
!= Not equal Left to right
& Bitwise AND Left to right
^ Bitwise exclusive OR Left to right
| Bitwise OR Left to right
&& Logical AND Left to right
|| Logical OR Left to right
? : Conditional Right to left
= Assignment Right to left
*=, /=,%=, +=, -=, &=, ^=, |= Compound assignment Right to Left
, Comma Left to right
Lowest Precedence